package environment;

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Line2D;

public class Line {
	Point p1, p2;
	
	public Line(Point p, Point otherP)
	{
		p1 = p;
		p2 = otherP;
	}
	
	public Point getCenterPoint()
	{
		double x,y;
		x = (p1.x + p2.x) / 2;
		y = (p1.y + p2.y) / 2;
		return new Point((int)x,(int)y);
	}
	
	public Point get1ThirdsPoint()
	{
		double x,y,xDiff,yDiff;
		xDiff = (Math.abs(p1.x - p2.x)) / 3;
		yDiff = (Math.abs(p1.y - p2.y)) / 3;
		
		if(p2.x <= p1.x)
		{
			xDiff = -xDiff;
		}
		if(p2.y <= p1.y)
		{
			yDiff = -yDiff;
		}
		
		x = p1.x + xDiff;
		y = p1.y + yDiff;
		
		return new Point((int)x,(int)y);
	}
	
	public Point get2ThirdsPoint()
	{
		double x,y,xDiff,yDiff;
		xDiff = (Math.abs(p1.x - p2.x)) / 3;
		yDiff = (Math.abs(p1.y - p2.y)) / 3;
			
		if(p2.x <= p1.x)
		{
			xDiff = -xDiff;
		}
		if(p2.y <= p1.y)
		{
			yDiff = -yDiff;
		}
		
		x = p1.x + 2*xDiff;
		y = p1.y + 2*yDiff;
		
		return new Point((int)x,(int)y);
	}
	
	public boolean intersects(Rectangle r)
	{
		Line2D.Double l = new Line2D.Double();
		l.setLine(p1, p2);
		return l.intersects(r);
	}
}
